package com.hupu.jrs.util

import android.content.Context
import android.os.Environment
import android.text.TextUtils
import java.io.File

/**
 * Created by sll on 2015/11/26.
 */
object ConfigUtil {

    private var cachePath: String? = null

    private var uploadPath: String? = null

    private var picSavePath: String? = null

    fun getCachePath(): String? {
        if (!TextUtils.isEmpty(cachePath)) {
            return cachePath
        }
        cachePath = (Environment.getExternalStorageDirectory().absolutePath
                + File.separator
                + "gzsll"
                + File.separator
                + "cache"
                + File.separator)
        val cache = File(cachePath!!)
        if (!cache.exists()) {
            cache.mkdirs()
        }
        return cachePath
    }

    fun getUploadPath(): String? {
        if (!TextUtils.isEmpty(uploadPath)) {
            return uploadPath
        }
        uploadPath = (Environment.getExternalStorageDirectory().absolutePath
                + File.separator
                + "gzsll"
                + File.separator
                + "upload"
                + File.separator)
        val upload = File(uploadPath!!)
        if (!upload.exists()) {
            upload.mkdirs()
        }
        return uploadPath
    }

    fun getPicSavePath(context: Context): String? {
        if (!TextUtils.isEmpty(picSavePath)) {
            return picSavePath
        }
        picSavePath = (Environment.getExternalStorageDirectory().absolutePath
                + File.separator + SettingPrefUtil.getPicSavePath(context)
                + File.separator)
        val file = File(picSavePath!!)
        if (!file.exists()) {
            file.mkdirs()
        }
        return picSavePath
    }
}
